#include <iostream>
#include <string>
#include "registers.h"
//#include "memory.h"
#include "util.h"
#include "fmap.h"
#include "op.h"
#include "stdio.h"
#include <boost/xpressive/xpressive.hpp>
#include <map>

using namespace std;
using namespace boost::xpressive;

void foo(object f) {
	cout << *(char*)(f);
}

int main(int argv[]) {
	initFuncMap();

	bool FALSE = false;
	bool TRUE = true;

	cout << "Welcome to iASM \n"
		 << "Console Mode\n";

	string cmd("");

	sregex rex = sregex::compile("([A-Z]+)(?:\\s+R([A-F0-9]{2}))(?:,\\s+(R){0,1}([A-F0-9]+)){0,1}");
    smatch what;
	do {  
		cmd.clear();
		cout << "> ";
		getline(cin, cmd);
		//cin.clear();
		if(regex_match(cmd, what, rex)) {
			cout << what[0] << '\n'; // whole match
			cout << what[1] << '\n'; // first capture
			cout << what[2] << '\n'; // second capture
			cout << parseInt(what[2].str()) << '\n';
			byte a = (byte)parseInt(what[2].str());
			ushort b = 0;
			if(what.size() > 4) {
				cout << what[3] << '\n'; // fourth capture
				cout << parseInt(what[3].str()) << '\n';
				b = parseInt(what[3].str());
			}
			cout << (int)a << " " << (int)b << '\n';
			runC(what[1].str(), a, b);
			//funcs[what[1].str()](&a, &b, &FALSE, &FALSE);
			reg* r = getReg(a);
			byte ans, ans2;
			r->get(&ans, &ans2);
			cout << (int)(ans) << ' ' << (int)(ans2) << '\n';
		}
	} while(cmd != "Ex");

	return 0;
}